package com.jd.mason.threadPool;


import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;

/**
 * 自定义线程池
 * @author mason
 *
 */
public class MyThreadPool<Job extends Runnable> implements ThreadPool<Job>{
	// 线程池维护工作者线程的最大数量
    private static final int MAX_WORKER_NUMBERS = 10;
    // 线程池维护工作者线程的默认值
    private static final int DEFAULT_WORKER_NUMBERS = 5;
    // 线程池维护工作者线程的最小数量
    private static final int MIN_WORKER_NUMBERS = 1;
    // 维护一个工作列表,里面加入客户端发起的工作
    private final LinkedList<Job> jobs = new LinkedList<Job>();
    // 工作者线程的列表
    private final List<Worker> workers = Collections.synchronizedList(new ArrayList<Worker>());
    // 工作者线程的数量
    private int workerNum;
    // 每个工作者线程编号生成
    private AtomicLong threadNum = new AtomicLong();
    
    public MyThreadPool() {
		this.workerNum = DEFAULT_WORKER_NUMBERS;
		//TODO
	}
    
    public MyThreadPool(int workers) {
    	this.workerNum = workers;
    	//TODO
    }

	@Override
	public void shutdown() {

	}

	@Override
	public void addWorkers(int num) {

	}

	@Override
	public void removeWorker(int num) {
		
	}

	@Override
	public void getJobSize() {
		
	}

	@Override
	public void execute(Job job) {
		
	}
	
	private class Worker implements Runnable {

		@Override
		public void run() {
			synchronized (jobs) {
				try {
					jobs.wait();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				Job job = jobs.poll();
				job.run();
			}
		}
		
	}
}
